<template>
  <div class="box2">
    <div class="title">
      <p>年龄比例</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <!-- 图形图标的容器 -->
    <div style="width: 200px; height: 200px" ref="charts"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
//引入echarts
import * as echarts from 'echarts'
let charts = ref()
//组件挂载完毕初始化图形图标
onMounted(() => {
  let mycharts = echarts.init(charts.value, 'dark')
  mycharts.resize({
    width: 400,
    height: 250,
  })
  let option = {
    title: {
      text: 'ECharts 入门示例',
    },
    backgroundColor: {
      type: 'radial',
      x: 0.3,
      y: 0.3,
      r: 0.8,
      colorStops: [
        {
          offset: 0,
          color: '#f7f8fa',
        },
        {
          offset: 1,
          color: '#cdd0d5',
        },
      ],
    },
    itemStyle: {
      // 点的颜色。
      color: 'red',
    },
    emphasis: {
      itemStyle: {
        // 高亮时点的颜色。
        color: 'blue',
      },
      label: {
        show: true,
        // 高亮时标签的文字。
        formatter: 'This is a emphasis label.',
      },
    },
    tooltip: {},
    legend: {
      data: ['销量'],
    },
    xAxis: {
      data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'],
    },
    yAxis: {},
    series: [
      {
        name: '销量',
        type: 'bar',
        data: [5, 20, 36, 10, 10, 59],
      },
    ],
  }

  mycharts.setOption(option)
})
</script>

<style scoped lang="scss">
.box2 {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;

  .title {
    margin-left: 20px;

    p {
      color: white;
      font-size: 20px;
    }
  }
}
</style>
